﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Track : System.Web.UI.Page
{
    String id;
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (Request["id"] != null)
        {
            id = Request["id"];
            List<Util.TrackInfo> oneTrack = new List<Util.TrackInfo>();
            BLL.Tracks forRep = new BLL.Tracks();
            oneTrack.Add(forRep.getTrack(id));
            ChangedTrack.DataSource = oneTrack;
            ChangedTrack.DataBind();
            if (!oneTrack[0].Visible)
            {
                IsVisibleCheckBox.Text = "Показывать трек";
            }
            
        }

    }
    protected void SaveChange_Click(object sender, EventArgs e)
    {
        if (IsDeletingCheckBox.Checked)
        {
            if (new BLL.Tracks().deleteTrack(id))
            {
                Response.Redirect("~/MyTracks.aspx");
            }
            else
            {
                InfoLabel.Text = "Трек не удален по неизвестной причине. Обратитесь к администрации сайта.";
            }
            return;
        }
        if (IsVisibleCheckBox.Checked) 
        {
            new BLL.Tracks().changeVisebleMode(id);
        }
        double tmp  = 0;
        if (TrackName.Text.Trim().Length != 0 && Price.Text.Trim().Length != 0 && Double.TryParse(Price.Text, out tmp))
        {
            new BLL.Tracks().updateTrack(new Util.TrackInfo() { TrackID = id, Name = TrackName.Text, Price = Price.Text });
        }
        else
            InfoLabel.Text = "Косяк, ВАся!";
        Response.Redirect("~/Track.aspx/?id=" + id);
    }
}